<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>" >
		<!--[if lte IE 6]></base><![endif]-->
		<title>广东科学技术职业学院考生报到系统<s:property
				value="%{#session.college.collegesName}" />
		</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link href="css/newindex.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="css/jquery-ui-1.8.5.custom.css"
			type="text/css" />
		<style>
			.my-dialog .ui-dialog-titlebar-close {
				display: none;
			}
		</style>
		<script src="js/jquery-1.5.js" language="javascript">
</script>
		<script src="js/jquery-ui-1.8.5.custom.min.js" language="javascript">
</script>
		<script src="js/newpublic.js" language="javascript">
</script>
		<script src="js/table.js" language="javascript">
</script>
 	<script src="js/ajaxfileupload.js" language="javascript">
</script>

		<script>
var result = null;//查询结果
function chooseSigleImport() {
	$("#execute").hide();
	$("#stuPayList").hide();
	$("#d1").show();
	$("#d2").hide();
}
function chooseLotImport() {
	$("#execute").show();
	$("#d1").hide();
	$("#d2").show();
	$("#showResult").hide();
	$("#queryResult").html("");
	//$("#stuPayList").show();
}

$(function() {
	$("#a").attr("checked",true);
	$("#execute").button();
		$("#content").draggable( {
		cancel : ".contable"
	});
	//动态加载logo
	$("#content .subjectlogo").css("background-image","url(<%=basePath%>/newimages/${sessionScope.college.collegeLogo})");
	
	$("#search").unbind("click").click(function() {
		$("#queryResult").html("");
		var examCode = $("#examCode_input").val();
		var studentName = $("#studentName_input").val();
		var idCode = $("#idCode_input").val();
		if (examCode == "" && studentName == "" && idCode == "") {
			//没有输入查询内容
			alert("请输入查询条件")
		} else if (examCode != "" && examCode.length < 5) {
			alert("准考证不能少了5位")
		} else if (idCode != "" && idCode.length < 5) {//身份证长度限制
			alert("身份证号码不能少了5位")
		} else {
			showProgressBar(true)//显示进度圈
			$.post("json/financeAction!queryStudentInfo", {
				'examCode' : examCode,
				'studentName' : studentName,
				'idCode' : idCode,
				"date" : new Date()
			}, function(data) {
				showResult(data)
				showProgressBar(false)//隐藏进度圈
				})
		}
	})
})
var students;//查询学生的结果
//显示查询结果
function showResult(data) {
	result = eval("(" + data.result + ")");
	if (result.length <= 0){
		$("#queryResult").html("没有查到符合条件的同学!")
		$("#showResult").hide();
		return;
	}
	students=result;
	$("#queryResult").html("查询结果：")
	clearMessage();
	for ( var i = 0; i < result.length; i++) {
		$("#progressBar").hide();
		$("#showResult").show();
		var stuName = result[i].studentName;
		var examcode = result[i].examCode;
		var idCode = result[i].idCode;
		var unpaidFee = result[i].unpaidFees;
		var studentId=result[i].studentId;
		var feePayable=result[i].feePayable;
		var tr;
		if (i % 2 != 0) {
			tr = '<tr style="background-color:#deefff" name="showStudentMessage">';
		} else {
			tr = '<tr style="background-color:#ffffff" name="showStudentMessage">';
		}

		tr += '<td width="42" align="center">' + (i + 1)
				+ '</td><td align="center">' + stuName
				+ '</td><td align="center">' + examcode
				+ '</td><td align="center">' + idCode
				+ '</td><td align="center">' + feePayable
				+ '元</td><td align="center"><font color="red">' + unpaidFee
				+ '元</font></td><td align="center"><a href="javascript:findStu('
				+ i + ')">修改欠费</a></td></tr>';
		$("#infoTable").append($(tr));
	}

}

//显示进度圈，当isShow为false时不显示,true则显示
function showProgressBar(isShow) {
	if (isShow) {
		$("#progressBar").show();
	} else {
		$("#progressBar").hide();
	}
}
//i 为学生信息在students的位置
function findStu(i) {

		var stu =students[i];
		$("#stuNameResult").html(stu.studentName);
		$("#examCodeResult").html(stu.examCode);
		$("#idCodeResult").html(stu.idCode);
		$("#feeResult").html(stu.feePayable);
		$("#unpaidFeeResult").val(stu.unpaidFees);
		$("#updateUserPaymentDialog").show();
		$("#updateUserPaymentDialog").dialog( {
			modal : true,
			width : 450,
			buttons : {
				"确定" : function() {
					updateStu(stu.studentId,stu.examCode);
				},
				"取消" : function() {
					$("#updateUserPaymentDialog").hide()
					$("#updateUserPaymentDialog").dialog("close");
				}
			}
		})
}

function updateStu(studentId,examcode) {
	var unpaidFee = $("#unpaidFeeResult").val();
	if (unpaidFee == '') {
		alert("欠费金额不能为空!");
		return;
	}else if(parseFloat(unpaidFee)>parseFloat($("#feeResult").html())){
		alert("欠款不能大于应该缴金额！")
		return;
	}
	
	$.post("json/financeAction!updatePayment", {
		"studentId" : studentId,
		"unpaidFees" : unpaidFee
	}, function(data) {
		if(!eval(data.result)){
			alert("更新失败！可能原因是欠费大于学费，或学生欠费情况不存在或服务器内部错误")
			return
		}
		alert("修改成功!");
		$("#updateUserPaymentDialog").hide()
		$("#updateUserPaymentDialog").dialog("close");

		$.post("json/financeAction!queryStudentInfo", {
			'examCode' : examcode,
			'studentName' : '',
			'idCode' : '',
			"date" : new Date()
		}, function(data) {
			showResult(data)
			showProgressBar(false)//隐藏进度圈
			})

	})
}

//清除数据
function clearMessage() {
	$("tr[name='showStudentMessage']").remove();

}
$(function() {

	$("#unpaidFeeResult").keyup(function() {//欠款金额限制只能输入数字
				$(this).val($(this).val().replace(/[^0-9]/g, ""))
			})

	$("#examCode_input").keyup(function() {//准考证限制只能输入数字
				$(this).val($(this).val().replace(/[^0-9]/g, ""))
			})
	$("#oneKeyAssignDormButton").button();
})
//一键分配宿舍
function oneKeyAssignDorm() {
	if(confirm("本次操作将为本学院所有已缴费但尚未分配宿舍的学生自动分配宿舍，确定执行此操作？？")){
		$("#onekeyAssignDormDiv").show();
		$("#assignInfo").html("");
		$("#onekeyAssignDormDiv").dialog( {
			modal : true,
			width : 700,
			height:200,
			dialogClass : "my-dialog",
			buttons : {
				'完成' : function() {
					$("#onekeyAssignDormDiv").dialog("close")
					$("#onekeyAssignDormDiv").hide();
				}
			}
		})
		dlBtnEnable(false);
		$("#assignProgress").show();
		
		$.post("json/onekeyAssignDormAction", {
			'date' : new Date()
		}, function(data) {
			dlBtnEnable(true);
			$("#assignInfo").html("执行成功！本次操作成功为"+data.result+"位学生自动分配了宿舍");
			$("#assignProgress").hide();
		})
	}
}
//控制按钮是否可用的函数.

function dlBtnEnable(enable)

{

	var dlgButton = $('.ui-dialog-buttonpane button');

	if (enable) {

		dlgButton.attr('disabled', '');

		dlgButton.removeClass('ui-state-disabled');

	} else {

		dlgButton.attr('disabled', 'disabled');

		dlgButton.addClass('ui-state-disabled');

	}

}

function addPaymentExcel(){
//批量导入宿舍
	
	var file=$("#upload").attr("value");
	if(file==null || file==""){
		alert("请先选择上传的文件!");
		return;
	}
	var excel=file.substring(file.lastIndexOf(".")); 
	if(excel!=".xls" && excel!=".xlt"){
		alert("请上传'.xls格式的Excel文件!'");
		return;
	}
	
	$("#importErrorDiv").hide(); 
	$("#checkingImage").hide();//显示对与错的图片
	$("#checkingProgress").show();//显示处理进度条
	$("#importMessage").html("")
	//显示处理窗口
	$("#doLotImportDiv").show();
	$("#doLotImportDiv").dialog({
		modal: true,
		width:500,
		height:400,
		dialogClass: "my-dialog",
		buttons:{
			'完成':function(){
				$("#doLotImportDiv").dialog("close")
			}}
	})
	dlBtnEnable(false);
	//批量导入宿舍
	 $.ajaxFileUpload({
                     url:'json/uploadPaymentExcel', //你处理上传文件的服务端
                     secureuri:false,
                     fileElementId:'upload',
                     dataType: 'json',
                     success: function (data, status) {
		 			 error=eval("("+data.error+")");
		 		if(error.length<=0){
		 			//没有错误
		 			$("#checkingImage").show();
		 			$("#checkingProgress").hide();
		 			$("#checkingImage").attr("src","images/right.png")
		 			$("#importMessage").html("<font size='+3' color='red'>导入成功</font>")
		 			var payments=eval("("+data.result+")");
		 			for(var i=0;i<payments.length;i++){
		 				showAddStuPayment(payments[i])
		 			}
		 			updateResultIndex()
		 			
		 		}else{
		 			
		 			 var table=$("#importErrorTable")
		 			 $("#importMessage").html("<font size='+3' color='red'>导入失败！</font>")
		 			 $("table#importErrorTable tr:gt(0)").remove();
                        		 for(var i=0;i<error.length;i++){	 
                               	var tr='<tr><td align="center">'+(i+1)+'</td><td align="left" ><font color="red">'+error[i]+'</font></td></tr>';
                        		 	table.append($(tr));
                        		 }
                        		 	$("table#importErrorTable tr:gt(0):even").css('background','#deefff'); 
						$("table#importErrorTable tr:gt(0):odd").css('background','#fff');
						$("#checkingImage").attr("src","images/error.png")
						$("#checkingImage").show();
						$("#checkingProgress").hide();
						$("#importErrorDiv").show();
						
		 		}
		 		dlBtnEnable(true);

                     },
			error: function (data, status, e)
			{ 
				//for(a in data){
			//		alert(data[a])
			//	}
				alert("上传失败！"+e);
				$("#doLotImportDiv").dialog("close");
				dlBtnEnable(true);
			}
                })
	
	//uploadDormExcel();

}

function showAddStuPayment(stu) {
	$("#stuName").val("");
	$("#stuExamCode").val("");
	$("#stuUnpaidFee").val("");
	$("#stuPayList").show();
	if(typeof stu !='object')
		stu=eval("("+stu+")");		
	var name = stu.studentName;
	var examcode = stu.examCode;
	var unpaidFees = stu.unpaidFees;
	var feePayable=stu.feePayable
	var tr=	'<tr><td align="center" name="addRecodeIndex"></td><td align="center">'+name+'</td><td align="center"> '+examcode+'</td><td align="center">'+feePayable+'</td><td align="center"><font color="red">'+unpaidFees+'</font></td></tr>';
	$("#stuAddTable tr:eq(0)").after($(tr))
	$("table#stuAddTable tr:gt(0):even").css('background','#deefff'); 
	$("table#stuAddTable tr:gt(0):odd").css('background','#fff');
}
function updateResultIndex(){
	$("td[name='addRecodeIndex']").each(function(i,v){
		$(this).html(i+1)
	})
	
}

function exportPayExcel() {
		
		$("#import_pay_excel_form").attr("action","exportPaymentExcelDemo.action").submit();
	}
</script>
	</head>

	<body onload="fixPNGAll()">
		<jsp:include page="common_head.jsp" />
		<div id="content">
			<!--当前位置CSS-->
			<div class="top">
				<div class="topleft">
					<div class="dan">
						<div>
							当前位置>财务管理
						</div>
					</div>
					<div class="F5">
						<img src="newimages/F5.png" />
					</div>
				</div>
				<div class="topright">
					<div class="toprightmin"></div>
					<div class="toprightmax"></div>
					<div class="toprightclose" onclick="if(confirm('是否确定退出！')){location.replace('loginoutAction')}" title="点击退出"></div>
				</div>
			</div>
			<!---->
			<!--内容-->
			<div class="condiv">
				<div class="subjectlogo">
					<!--每学院Logo-->
					<div class="submenu">

					</div>

					<div class="contable">
						<div
							style="float: right; margin-top: 10px;width: 250px;display: none;">
							<input type="button" value="一键分配宿舍" onclick="oneKeyAssignDorm()"
								id="oneKeyAssignDormButton" />
							<br />
							<font style="font-size: 12px; color: red;">为所有已缴费学生自动分配宿舍</font>
						</div>
						<div class="title" style="margin-left: 400px;margin-right: auto;width: 150px">
							财务管理
						</div>

						<!--数据库读数据-->
						<table width="80%" border="0" align="center" cellpadding="1"
							cellspacing="5" height="70">
							<tr >
								<td width="66%" height="80" align="right">
									<div>
										<table width="60%" align="center" id="d1" >
											<tr>
												<td width="30%" align="right">
													姓名：
												</td>
												<td width="29%">
													<input type="text" size="15" id="studentName_input" />
												</td>
											</tr>
											<tr>
												<td align="right">
													身份证：
												</td>
												<td>
													<input type="text" size="15" id="idCode_input" />
												</td>
											</tr>
											<tr>
												<td align="right">
													准考证：
												</td>
												<td>
													<input type="text" size="15" id="examCode_input" />
												</td>
												<td>
													<input type="button" value="查询" id="search" style="float: left"/>
												</td>
											</tr>
										</table>

										<div id="d2" style="display: none; padding-left: 10px;">
											<table>
												<tr>
													<td width="80%">
														<form action="" id="import_pay_excel_form" method="post"
															enctype="multipart/form-data">
															<input type="file" name="upload" id="upload" />
															&nbsp;&nbsp;
															<input type="button" value="下载模板" onclick="exportPayExcel()" />
															&nbsp;&nbsp;&nbsp;&nbsp;
														</form>
													</td>
													<td align="right" width="20%">
														<input type="button" value="执行" id="execute" onclick="addPaymentExcel()"/>
													</td>
												</tr>
												<tr><td><font color="red">请选择下载模版,填写内容后再导入</font> </td></tr>
											</table>
										</div>
										
									</div>
								</td>
								<td width="35%" style="border-left: 1px dotted red;">
									<div>
										<input name="a" type="radio" value="" checked="checked" id="a"
											onclick="chooseSigleImport()" />
										学生缴费信息查询
									</div>
									<div>
										<input name="a" type="radio" value=""
											onclick="chooseLotImport()" />
										批量更新缴费信息
									</div>
								</td>
							</tr>
						</table>

						<div id="data">
							<div id="progressBar" style="display: none">
								<!-- 进度圈 -->
								<center>
									<img src="<%=request.getContextPath()%>/images/loading.gif" />
								</center>
							</div>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<span style="color: #F00; font-size: 16px;" id="queryResult"></span>
							<div id="showResult" style="margin-top: 20px; display: none;">
								<!--ID没有任何样式，只是控制显示-->
								<table id="infoTable" width="700" border="0" align="center"
									cellpadding="1" cellspacing="1" class="t1"
									style="border: 1px solid #5cb0ff;">
									<tr>
										<th width="42" align="center">
											序号
										</th>
										<th width="103" align="center">
											姓名
										</th>
										<th width="152" align="center">
											准考证
										</th>
										<th width="167" align="center">
											身份证
										</th>
										<th width="110" align="center">
											应缴学费
										</th>
										<th width="110" align="center">
											欠费金额
										</th>
										<th width="120" align="center">
											操作
										</th>
									</tr>
								</table>
							</div>
							<!--数据库读数据结束-->
							<!--************************************************************-->
							<div id="stuPayList" style="display: none">
								<h2 style="text-align: center; color: red;">
									更新欠费记录
								</h2>
								<table width="700" height="31" border="0" align="center"
									cellpadding="0" cellspacing="1" class="t1"
									style="margin-top: 20px; border: 1px solid #5cb0ff;"
									id="stuAddTable">
									<tr style="color: #000;">
										<th height="20" align="center">
											序号
										</th>
										<th height="20" align="center">
											姓名
										</th>
										<th height="20" align="center">
											准考证号
										</th>
										<th height="20" align="center">
											学费
										</th>
										<th height="20" align="center">
											欠费金额
										</th>
									</tr>
								</table>
							</div>
				
							<!--************************************************************-->
						</div>
					</div>
				</div>
				<!--每学院Logo-->
			</div>
			<!---->
			<!---->
			<div class="condiv"
				style="width: 997px; position: relative; height: 20px; min-height: 20px; text-align: center;">
				<a href="computer/computer.html" target="_blank">计算机学院程序员之家</a>
			</div>
			<!---->
			<!--低部-->
			<div class="bottom">
				&nbsp;
			</div>
			<!---->
		</div>
		</div>

		<div id="updateUserPaymentDialog" title="修改用户缴费信息"
			style="display: none;">
			<table width="100%" id="d1" border="0">
				<tr>
					<td align="right">
						姓名:
					</td>
					<td>
						<div id="stuNameResult"></div>
					</td>
				</tr>
				<tr>
					<td align="right">
						准考证：
					</td>
					<td>
						<div id="examCodeResult"></div>
					</td>
				</tr>
				<tr>
					<td align="right">
						身份证：
					</td>
					<td>
						<div id="idCodeResult"></div>
					</td>
				</tr>
				<tr>
					<td align="right">
						应缴费用：
					</td>
					<td id="feeResult">
						
					</td>
				</tr>
				<tr>
					<td align="right">
						欠费金额：
					</td>
					<td>
						<input id="unpaidFeeResult" type="text" size="16" value="" />元
					</td>
				</tr>
			</table>
		</div>
	
		
		<!--                   批量导入时的弹出div -->
		<div id="doLotImportDiv" title="批量导入缴费信息" style="display: none">
			<table width="100%">
				<tr>
					<td align="left">
						<font color="red" size="2px">正在导入。。。</font>
						<br />
					</td>
					<td align="right">
						<img src="images/right.png" alt="" width="30px" id="checkingImage" />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<img src="images/progressBar.gif" alt="正在导入。。。"
							id="checkingProgress" />
						<div id="importMessage">

						</div>
					</td>
				</tr>
				<tr>
					<td>
						
						<div id="importErrorDiv" style="display: none;overflow: auto">
							<table id="importErrorTable" width="100%" border="0" style=""
								class="t1">
								<tr style="font-size: 18px; font-weight: bold; color: red">
									<th width="10%" align="center">
										序号
									</th>
									<th align="center">
										错误信息
									</th>
								</tr>
								<tr>
									<td align="center">
										1
									</td>
									<td align="center">
										宿舍号重复
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
			<div>

	<div id="onekeyAssignDormDiv" style="display: none" title="正在自动分配宿舍">
		
		<center>
			<p style="font-size: 12px;color: red">正在分配，请稍等。。。</p>
			<img src="images/progressBar.gif" alt=""  id="assignProgress"/>
			<p id="assignInfo" style="font-size: 16px;color: red"></p>
		</center>
		</div>
			</div>
		</div>
		
		
	</body>
</html>
